<?php
require "../../../../global.php";


//----------------------------------------------------
//  接收数据
//  Receive the data
//----------------------------------------------------
$billno = $_GET['billno'];
$amount = $_GET['amount'];
$mydate = $_GET['date'];
$succ = $_GET['succ'];
$msg = $_GET['msg'];
$attach = $_GET['attach'];
$ipsbillno = $_GET['ipsbillno'];
$retEncodeType = $_GET['retencodetype'];
$currency_type = $_GET['Currency_type'];
$signature = $_GET['signature'];

//'----------------------------------------------------
//'   Md5摘要认证
//'   verify  md5
//'----------------------------------------------------
$content = $billno . $amount . $mydate . $succ . $ipsbillno . $currency_type;
//请在该字段中放置商户登陆merchant.ips.com.cn下载的证书
$cert = '36451620901856065970269330053246181842887948974683586506701057676567422219322046647065958403072037230625137727476541950060891824';
$signature_1ocal = md5($content . $cert);

if ($signature_1ocal == $signature)
{
	//----------------------------------------------------
	//  判断交易是否成功
	//  See the successful flag of this transaction
	//----------------------------------------------------
	if ($succ == 'Y')
	{
		/**----------------------------------------------------
		*比较返回的订单号和金额与您数据库中的金额是否相符
		*compare the billno and amount from ips with the data recorded in your datebase
		*----------------------------------------------------
		
		if(不等)
			echo "从IPS返回的数据和本地记录的不符合，失败！"
			exit
		else
			'----------------------------------------------------
			'交易成功，处理您的数据库
			'The transaction is successful. update your database.
			'----------------------------------------------------
		end if
		**/
		//更新商户数据库内容
		
			require RootDir."/inc/dabase_mysql.php";
			$mydb=new YYBDB();
			preg_match("/^[a-zA-Z][0-9]+/",$billno,$orderAr);
			$billnol=$orderAr[0];
			$payflag=str_replace($billnol,"",$billno);
			//定金支付条件
				$sql2="earnestmoney=".$amount.",paytimeearnestmoney=".time().",earnbizhong='".$currency_type."',paytype='环讯',isconfim=1";
				$paytype="dj";
				
				if($payflag!="")
				{
					if($payflag=="je2")//第二次支付条件
					{
						$sql2="balance=".$amount.",paytimebalance=".time().",balancebizhong='".$currency_type."',balancepaytye='环讯',balanceisconfim=1";
						$paytype="je2";
					}
					if($payflag=="je3")
					{
						$sql2="je3=".$amount.",je3paytime=".time().",je3bizhong='".$currency_type."',je3paytype='环讯',je3isconfim=1";
						$paytype="je3";
					}
					if($payflag=="je4")
					{
						$sql2="je4=".$amount.",je4paytime=".time().",je4bizhong='".$currency_type."',je4paytype='环讯',je4isconfim=1";
						$paytype="je4";
					}
				}
			


			$sql="update ".$SystemConest[7]."orderpaylist set ".$sql2."	  where orderno='".$billnol."'";
			 $mydb->db_query($sql);
			 $res=$mydb->db_query("select * from ".$SystemConest[7]."tourorder where orderno='".$billnol."'");
			 $rs=$mydb->db_fetch_array($res);
			 //支付成功，执行发送邮件操作
			 echo "<iframe  src='/dszSendMail_sendMailInfo_type_paysuss_orderno_".$billnol."_paytype_网银在线支付_djorwk_".$paytype."_email_".$rs["nuseremail"]."' 
frameborder=0 scrolling=no width=1 height=1></iframe>";
			 unset($rs);
			//这里可以写支付后的返回给用户的界面
			 require RootDir."/inc/Uifunction.php";
			$url="/".Q."paytype_showpaysucctocustomer_orderno_".$billnol."_moneynum_".$amount."_bizhong_RMB_paytype_网银在线支付";
		   gourl($url,1);
	}
	else
	{
		echo '交易失败！';
		exit;
	}
}
else
{
	echo '签名不正确！';
	exit;
}
?>
